<?php 
	class ControllerMemoryCreateknowledge extends Controller {
		private $error = array();

		public function index() {
			$this->document->setTitle("createknowledge");
			$this->document->addStyle('admin/view/stylesheet/bootstrap-datetimepicker.min.css');
			$this->document->addScript('admin/view/javascript/bootstrap-datetimepicker.js');
			$this->document->addScript('admin/view/javascript/bootstrap-datetimepicker.zh-CN.js');
			if(($this->request->server['REQUEST_METHOD'] == 'POST')) {
				$info['kname']   = $this->request->post['kname'];
				$info['klabel']  = $this->request->post['klabel'];
				$info['ftime']   = $this->request->post['ftime'];
				$info['kdetail'] = $this->request->post['kdetail'];
				$info['user_id']  = $this->session->data['user_id']; 
				$this->load->model('knowledge/knowledge');
				if($kid=$this->model_knowledge_knowledge->addKnowledge($info)){
					$this->load->model('settingreview/settingreview');
					$this->load->model('complate/complate');
					$query = $this->model_settingreview_settingreview->getSettingreview($this->session->data['user_id']);
					if(empty($query)){
						$query = $this->config->get("setting_review");
					}
					$ftime = $this->model_knowledge_knowledge->getFirsttimebykid($kid);
					//调用complatetime类来决定复习时间
					$this->load->library("complatetime");
					$c_time = new complatetime($ftime,$query);
					$complatetime = $c_time->getComplatetime();
				};
				$result = $this->model_complate_complate->addComplate($complatetime,$kid,$this->session->data['user_id']);
				header('Content-Type:application/json; charset=utf-8');
                exit(json_encode($kid,0));
			}
			$data['maincontent'] = "创建新的知识点";
			$this->load->model('setting/setting');
			$defaultlabel = $this->model_setting_setting->getDefaultLabel($this->session->data['user_id']);
			$data['defaultlabel'] = $defaultlabel['defaultlabel'];
			$data['velknameurl'] = $this->url->link('memory/createknowledge/velkname','',true)."&token=".$this->session->data['token'];
			$data['header'] = $this->load->controller('common/headerin');
	 		$data['footerin'] = $this->load->controller('common/footerin');
	 		$data['footer'] = $this->load->controller('common/footer');
	 		$this->response->setOutput($this->load->view('memory/createknowledge', $data));
		}
		public function velkname(){
			if(($this->request->server['REQUEST_METHOD'] == 'POST')) {
				$kname = $this->request->post['kname'];
				$this->load->model('knowledge/knowledge');
				$results = $this->model_knowledge_knowledge->velkname($kname);
				header('Content-Type:application/json; charset=utf-8');
                exit(json_encode($results,0));
			}
		}
	}
 ?>